home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 401-425 / 417 / mostcurrent / clearspace.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  4KB  |  206 lines

  1. /* ClearSpace.c
  2.  *
  3.  * Programmed by: Peter A. Phelps 11/9/90
  4.  *
  5.  * See MostCurrent.doc for further info.
  6.  *
  7.  */
  8.  
  9. #include    <stdio.h>
  10. #include    <exec/types.h>
  11.  
  12. #define    ASSEMBLY    0x00004000
  13. #define    BASIC        0x00080000
  14. #define    MODULA2        0x01000000
  15. #define    OTHER        0x20000000
  16. #define    ESC            27
  17.  
  18. void    quit();
  19. FILE    *Index, *TmpIndex, *KeyNames, *NewKeyNames;
  20.  
  21. main()
  22. {
  23.     char    Tag[16], InChar;
  24.     int        i, Line, Button = 0;
  25.     SHORT    ThisFish = 0;
  26.     union
  27.     {
  28.         struct
  29.         {
  30.             ULONG    BitMask;
  31.             SHORT    FFDisk;
  32.             ULONG    AbsAdr;
  33.             SHORT    ContentsLength;
  34.             UBYTE    Space___The_Final_Frontier;
  35.         } Entry;
  36.         struct
  37.         {
  38.             UBYTE    Byte[13];
  39.         } ByteView;
  40.     } Record;
  41.  
  42.     if((Index = fopen("index.old","r")) == (struct FILE *)NULL)
  43.     {
  44.         printf("index.old not found!\nSee MostCurrent.doc\n");
  45.         quit(0);
  46.     }
  47.  
  48.     if((KeyNames = fopen("KeyNames.old","r")) == (struct FILE *)NULL)
  49.     {
  50.         printf("KeyNames.old not found!\nSee MostCurrent.doc\n");
  51.         quit(1);
  52.     }
  53.  
  54.     for(i=0;i<29;i++)
  55.         while(getc(KeyNames) != '\n');
  56.  
  57.     fgets(Tag,16,KeyNames);
  58.  
  59.     if(strcmp(Tag,"Other code     "))
  60.     {
  61.         printf("KeyNames.old has already been modified by this\n");
  62.         printf("program.  Rename KeyNames.old to KeyNames, and\n");
  63.         printf("see MostCurrent.doc\n");
  64.         quit(2);
  65.     }
  66.  
  67.     if((TmpIndex = fopen("index.tmp","x")) == (struct FILE *)NULL)
  68.     {
  69.         printf("index already exists!\nSee MostCurrent.doc\n");
  70.         quit(2);
  71.     }
  72.  
  73.     if((NewKeyNames = fopen("KeyNames","x")) == (struct FILE *)NULL)
  74.     {
  75.         printf("KeyNames already exists!\nSee MostCurrent.doc\n");
  76.         quit(3);
  77.     }
  78.  
  79.     printf("Please enter the number of the button you wish to give up\n");
  80.     printf("\n1) Assembly\n2) Basic\n3) Modula-2\n\n");
  81.  
  82.     while(Button < 1 || Button > 3)
  83.     {
  84.         printf("Button Number (1-3): ");
  85.         scanf("%d",&Button);
  86.     }
  87.  
  88.     fseek(KeyNames,0,0);
  89.  
  90.     Line=0;
  91.     switch(Button)
  92.     {
  93.         case 1:
  94.             while(++Line<15)
  95.             {
  96.                 InChar = '\0';
  97.                 while(InChar != '\n')
  98.                     putc((InChar = getc(KeyNames)),NewKeyNames);
  99.             }
  100.             Line--;
  101.             for(i=0;i<15;i++)
  102.                 getc(KeyNames);
  103.             fprintf(NewKeyNames,"Basic          ");
  104.         case 2:
  105.             while(++Line<20)
  106.             {
  107.                 InChar = '\0';
  108.                 while(InChar != '\n')
  109.                     putc((InChar = getc(KeyNames)),NewKeyNames);
  110.             }
  111.             Line--;
  112.             for(i=0;i<15;i++)
  113.                 getc(KeyNames);
  114.             fprintf(NewKeyNames,"Modula-2       ");
  115.         case 3:
  116.             while(++Line<25)
  117.             {
  118.                 InChar = '\0';
  119.                 while(InChar != '\n')
  120.                     putc((InChar = getc(KeyNames)),NewKeyNames);
  121.             }
  122.             Line--;
  123.             for(i=0;i<15;i++)
  124.                 getc(KeyNames);
  125.             fprintf(NewKeyNames,"Other code     ");
  126.             break;
  127.     }
  128.  
  129.     while(++Line<30)
  130.     {
  131.         InChar = '\0';
  132.         while(InChar != '\n')
  133.             putc((InChar = getc(KeyNames)),NewKeyNames);
  134.     }
  135.     for(i=0;i<15;i++)
  136.         getc(KeyNames);
  137.     fprintf(NewKeyNames,"Most Current   ");
  138.  
  139.     do
  140.         if((InChar = getc(KeyNames)) != EOF)
  141.             putc(InChar,NewKeyNames);
  142.     while(InChar != EOF);
  143.     fclose(NewKeyNames);
  144.     fclose(KeyNames);
  145.  
  146.     printf("Revising keys on\n\n");
  147.  
  148.     while((InChar = getc(Index)) != EOF)
  149.     {
  150.         for(i=0;i<13;i++)
  151.         {
  152.             Record.ByteView.Byte[i] = InChar;
  153.             InChar = getc(Index);
  154.         }
  155.         switch(Button)
  156.         {
  157.             case 1:
  158.                 if(Record.Entry.BitMask & ASSEMBLY)
  159.                     Record.Entry.BitMask |= OTHER;
  160.                 Record.Entry.BitMask &= ~ASSEMBLY;
  161.                 if(Record.Entry.BitMask & BASIC)
  162.                     Record.Entry.BitMask |= ASSEMBLY;
  163.             case 2:
  164.                 if(Button == 2 && Record.Entry.BitMask & BASIC)
  165.                     Record.Entry.BitMask |= OTHER;
  166.                 Record.Entry.BitMask &= ~BASIC;
  167.                 if(Record.Entry.BitMask & MODULA2)
  168.                     Record.Entry.BitMask |= BASIC;
  169.             case 3:
  170.                 if(Button == 3 && Record.Entry.BitMask & MODULA2)
  171.                     Record.Entry.BitMask |= OTHER;
  172.                 Record.Entry.BitMask &= ~MODULA2;
  173.                 if(Record.Entry.BitMask & OTHER)
  174.                     Record.Entry.BitMask |= MODULA2;
  175.                 break;
  176.         }
  177.         Record.Entry.BitMask &= ~OTHER;
  178.         for(i=0;i<13;i++)
  179.             putc(Record.ByteView.Byte[i],TmpIndex);
  180.         putc(0,TmpIndex);
  181.         if(Record.Entry.FFDisk != ThisFish)
  182.             printf("%c[AFish #%d\n",ESC,Record.Entry.FFDisk);
  183.         ThisFish = Record.Entry.FFDisk;
  184.     }
  185.     fclose(TmpIndex);
  186.     fclose(Index);
  187.  
  188.     printf("Program has completed noramally.\n");
  189.     printf("Please run 'MostCurrent' now\n");
  190. }
  191.  
  192. void    quit(point)
  193. {
  194.     switch(point)
  195.     {
  196.         case 3:
  197.             fclose(TmpIndex);
  198.         case 2:
  199.             fclose(KeyNames);
  200.         case 1:
  201.             fclose(Index);
  202.         case 0:
  203.             exit(FALSE);
  204.     }
  205. }
  206.